package com.roper.yygh.common.exception;

import com.roper.yygh.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Description: 全局统一异常类
 * Date:      2021/6/27 17:34
 * author:    LPH
 * version:   V1.0
 */
@ControllerAdvice
public class GloalException {

    // 当出现异常，就会执行异常代码
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    // 自定义异常  需要手动抛出
    @ExceptionHandler(HospitalException.class)
    @ResponseBody
    public Result error(HospitalException e) {
        e.printStackTrace();
        return Result.fail();
    }

}
